<template>
  <div>
    <!-- 地址列表 -->
    <van-address-list
      v-model="judgesID"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="onSelect"
    />
  </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'

export default {
  data() {
    return {
      // 选中那个框Id
      judgesID: 1,
      list: []
    }
  },
  created() {
    this.getlist()
  },
  methods: {
    //
    ...mapMutations(['addSelect', 'addModify', 'addlistk']),
    getlist() {
      const data = localStorage.getItem('list')
      this.list = JSON.parse(data)
      console.log(this.list)
      this.judgesID = this.judges
      this.addlistk()
    },
    // 添加地址
    onAdd(val) {
      this.$router.push('/addressedit')
    },
    // 修改触发
    onEdit(val) {
      //   console.log(a)
      this.addModify(val)
      this.$router.push('/edittheaddress')
    },
    // 	切换选中的地址时触发
    onSelect(val) {
      console.log(val)
      //   传值选中的id
      this.addSelect(val.id)
    }
  },
  computed: {
    //   获取数据和id值
    ...mapState(['judges'])
  }
}
</script>
<style lang="less" scoped>
</style>